<template>
  <div class="leftcontent" v-if="secondMenus.length > 0">
    <div class="leftmenu">
      <div class="item-list">
        <div 
          v-for="item in secondMenus" 
          :key="item.id"
          class="item"
          :class="{ 'sel': secondNavId == item.id}"
        >
          <div class="item-name" @click="selectMenuItem(item)">
            {{ item.name }}
          </div>
          <div class="sub-item-list" v-if="item.children && item.children.length > 0" >
            <div 
              v-for="subItem in item.children" 
              :key="subItem.id" 
              class="sub-item"
              :class="{ 'sel': thirdNavId == subItem.id }"
              @click.stop="selectSubMenuItem(subItem, item)"
            >
              - {{ subItem.name }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  data() {
    return {
    
    }
  },
  computed: {
  },
  watch: {
   
  },
  mounted() {
   
  },
  methods: {
    selectMenuItem(item) {
      let path = this.$route.path
      if (path.includes('detail')) {
        path = path.split('-')[0]
        this.$router.push(path + '/' + item.parentId + '?id=' + item.id)
        return
      }
      this.$router.push(path + '?id=' + item.id)
    },
    selectSubMenuItem(subItem, parent) {
      let path = this.$route.path
      if (path.includes('detail')) {
        path = path.split('-')[0]
        this.$router.push(path + '/' + parent.parentId + '?subId=' + subItem.id)
        return
      }
      this.$router.push(path + '?subId=' + subItem.id + '&id=' + parent.id)
    }
  }
}
</script>

<style lang="scss" scoped>
.leftcontent {
  width: 213px;
  float: left;
  border-top: 3px #365897 solid;
}

.leftmenu {
  background: #F8F8F8;
  .item-list {
    width: 213px;
  }
  .item {
    min-height: 40px;
    line-height: 40px;
    width: 213px;
    display: block;
    background: url(~@/assets/images/sysimages/5.jpg) no-repeat center bottom;
    background-color: #F8F8F8;
    color: #666;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    position: relative;

    .item-name {
      padding: 0 0 0 30px;
      border-left: 4px solid transparent;
      position: relative;
    }

    &.sel .item-name,
    &:hover .item-name {
      border-left: 4px solid #365897;
      background-color: #EFEEEA;
      color: #365897;
    }
    
    // 展开状态的背景色
    &.expanded:not(.sel) .item-name {
      background-color: #F0F0F0;
    }
    
    .sub-item-list {
      padding-bottom: 10px;
      // 添加过渡效果
      transition: max-height 0.3s ease, opacity 0.2s ease;
      overflow: hidden;
      display: none;
    }
    
    .sub-item {
      text-decoration: none;
      color: #0777db;
      font-size: 12px;
      font-weight: normal;
      padding: 0 0 0 30px;
      cursor: pointer;
      line-height: 24px;
      
      &.sel, 
      &:hover {
        color: #365897;
        font-weight: bold;
      }
    }
    &.sel .sub-item-list {
      display: block;
    }
  }
}
</style> 